package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardReport;
import com.qf.service.EsService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author lenovo
 * @version V1.0
 * @Date 2021/11/25 16:25
 */
@Component
public class UpdateLogLIstener {

    @Autowired
    private EsService esService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void updateLog(StandardReport report, Message message, Channel channel)  {

        //1.修改es的日志
        try {
            esService.updateLog(report);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //2.手动ack
            try {
                channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }











    }
}
